﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace wpf_buildtool
{
    /// <summary>
    /// UserControl1.xaml 的交互逻辑
    /// </summary>
    public partial class Toolbar_Build : ToolBar
    {
        public Toolbar_Build()
        {
            InitializeComponent();
        }
        //newProj
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog m_Dialog = new System.Windows.Forms.FolderBrowserDialog();
            var result = m_Dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                var path = m_Dialog.SelectedPath;


                if (buildtool.BuildTool.HaveProj(path))
                {
                    MessageBox.Show("alread have a  proj in here.");
                    return;

                }
                var b = buildtool.BuildTool.CreateProj(path);
                if (b)
                {
                    Plugin._IDE.SetData_String("__curProj", path);
                    Plugin._IDE.GetPipeline("_project").Send("changeProjPath", path);
                }
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog m_Dialog = new System.Windows.Forms.FolderBrowserDialog();
            var result = m_Dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                var path = m_Dialog.SelectedPath;


                if (buildtool.BuildTool.OpenProj(path) == false)
                {
                    MessageBox.Show("open a  proj error.");
                    return;

                }
                Plugin._IDE.SetData_String("__curProj", path);
                Plugin._IDE.GetPipeline("_project").Send("changeProjPath", path);
            }

        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var curproj = Plugin._IDE.GetData_String("__curProj");
            var data = buildtool.BuildTool.BuildProj(curproj, out string recv);
            Plugin._IDE.GetPipeline("output").Send("warn", "build asm");
            Plugin._IDE.GetPipeline("output").Send("msg", recv);

            Plugin._IDE.SetData_ByteArray("__curImage", data);
        }
        //save current
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Plugin._IDE.SaveCurFile();

        }
        //save all
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            Plugin._IDE.SaveAllFile();
        }
    }
}
